package com.ruoyi.project.baozhi.dept.controller;

import java.util.List;
import java.util.UUID;

import com.ruoyi.project.baozhi.box.service.BoxService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.baozhi.dept.domain.OrgDept;
import com.ruoyi.project.baozhi.dept.service.IOrgDeptService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * deptController
 * 
 * @author ruoyi
 * @date 2021-12-10
 */
@Controller
@RequestMapping("/baozhi/dept")
public class OrgDeptController extends BaseController
{
    private String prefix = "baozhi/dept";

    @Autowired
    private IOrgDeptService orgDeptService;

    @Autowired
    private BoxService boxService;

    @RequiresPermissions("baozhi:dept:view")
    @GetMapping()
    public String dept()
    {
        return prefix + "/dept";
    }

    /**
     * 查询dept列表
     */
    @RequiresPermissions("baozhi:dept:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrgDept orgDept)
    {
        startPage();
        List<OrgDept> list = orgDeptService.selectOrgDeptList(orgDept);
        return getDataTable(list);
    }

    /**
     * 导出dept列表
     */
    @RequiresPermissions("baozhi:dept:export")
    @Log(title = "dept", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrgDept orgDept)
    {
        List<OrgDept> list = orgDeptService.selectOrgDeptList(orgDept);
        ExcelUtil<OrgDept> util = new ExcelUtil<OrgDept>(OrgDept.class);
        return util.exportExcel(list, "dept数据");
    }

    /**
     * 新增dept
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存dept
     */
    @RequiresPermissions("baozhi:dept:add")
    @Log(title = "dept", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrgDept orgDept)
    {
        orgDept.setDeptId(UUID.randomUUID().toString().replace("-","").substring(0,8));

        return toAjax(orgDeptService.insertOrgDept(orgDept));
    }

    /**
     * 修改dept
     */
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") String deptId, ModelMap mmap)
    {
        OrgDept orgDept = orgDeptService.selectOrgDeptByDeptId(deptId);
        mmap.put("orgDept", orgDept);
        return prefix + "/edit";
    }

    /**
     * 修改保存dept
     */
    @RequiresPermissions("baozhi:dept:edit")
    @Log(title = "dept", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrgDept orgDept)
    {
        return toAjax(orgDeptService.updateOrgDept(orgDept));
    }

    /**
     * 删除dept
     */
    @RequiresPermissions("baozhi:dept:remove")
    @Log(title = "dept", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orgDeptService.deleteOrgDeptByDeptIds(ids));
    }

    @RequiresPermissions("baozhi:dept:bumenshuaxin")
    @Log(title = "dept", businessType = BusinessType.DELETE)
    @PostMapping( "/bumenshuaxin")
    @ResponseBody
    public int bumenshuaxin()
    {
        OrgDept orgDept=new OrgDept();
        List<OrgDept> list = orgDeptService.selectOrgDeptList(orgDept);
        return boxService.bumenshuaxin_danwei(list);

    }

}
